Query q;
ObjList ol;
Unit this;
int j;

this = owner.AsUnit;
if (!.IsValid) return;

q = ObjsInSight(this, "Peasant");
while (true)
{
	Sleep(9000);
	//ol = Intersect(ObjsInSight(this, "Unit"), ClassPlayerObjs("Unit", .player)).GetObjList();
        
        if(!q.IsEmpty){
        	ol = q.GetObjList();
	        //pr("Count: "+ol.count);
	        for ( j=0 ; j<ol.count ; j+=1 ){
	                Unit u, u2;
                        str class_unit;
	                u = ol[j].AsUnit;
                        //class_unit = "";
	                //if(u.IsHeirOf("Peasant")) {
	                //pr("race: "+u.race);
                        //pr("class: "+u.class);
	                Sleep(rand(1000)+100);
	                //if (u.race==Carthage){
                        	//if(u.class == "CVillager")
	                		//class_unit = "CBerberAssassin";
	                if (u.race==Iberia){
                        	if(u.class == "IVillager")
	                		class_unit = "IEliteGuard";
	                //} else if (u.race==Britain){
                        	//if(u.class == "BVillager")
	                		//class_unit = "BShieldBearer";
	                } else if (u.race==Germany){
                        	if(u.class == "TVillager")
	                		class_unit = "TAxeman";
	                } else if (u.race==Egypt){
                        	if(u.class == "EVillager")
	                		class_unit = "EAxetrower";
	                } else if (u.race==Gaul){
                        	if(u.class == "GVillager")
	                		class_unit = "GAxeman";
                                        //else if(u.class == "GWVillager")
                                        	//class_unit = "GWomanWarrior";                                        	
			//} else if(u.race==ImperialRome || u.race==RepublicanRome){
                        //	if(u.class == "RVillager")
	                //		class_unit = "RHastatus";
                        }
                                
	                if(class_unit != ""){
	                	u2 = Place(class_unit, u.pos, u.player);      
	                        CreateFeedback("Rage", this);
	                        SwapSelectedObj(u, u2);
	                        u.Erase();
	                        CreateFeedback("OffensiveTactics", u2.AsUnit());
	                        u2.AsUnit.SetPlayer(.player); 
                        }  

	        }
        }
	
}
